package com.hsmw.schedule.service;

import com.hsmw.schedule.mapper.HsmwOrderVehicleRequestMapper;
import com.hsmw.schedule.vo.RequestVo;
import com.hsmw.common.base.BaseService;
import com.hsmw.domain.HsmwOrderVehicleRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class HsmwOrderVehicleRequestService extends BaseService<HsmwOrderVehicleRequestMapper, HsmwOrderVehicleRequest> {
    @Autowired
    private HsmwOrderVehicleRequestMapper hsmwOrderVehicleRequestMapper;

    public List<RequestVo> findRequstListByOrderId(String orderId) {

        return hsmwOrderVehicleRequestMapper.findRequstListByOrderId(orderId);
    }

    public List<HsmwOrderVehicleRequest> expireTimerequestList() {
        return hsmwOrderVehicleRequestMapper.expireTimerequestList();
    }


    //比较并更新
    public boolean compareAndUpdate(HsmwOrderVehicleRequest request){
        HsmwOrderVehicleRequest hsmwOrderVehicleRequest = hsmwOrderVehicleRequestMapper.selectById(request.getId());

        if(request.getVersion() != hsmwOrderVehicleRequest.getVersion() ){
            return false;
        }
        request.setVersion(request.getVersion()+1);
        hsmwOrderVehicleRequestMapper.updateById(request);
        return true;
    }

    public List<HsmwOrderVehicleRequest> selectCancellist(HashMap param ) {
        return hsmwOrderVehicleRequestMapper.selectCancellist(param);
    }
}
